/**
 * Copyright 2009 University of  Washington
 * This code is released under the GPL version 3 - with a copy of the license included
 * @author Maya Hao Li
 *
 */
package seedpod.webapp.controller;

import java.util.ArrayList;

import seedpod.exceptions.SeedpodException;
import seedpod.model.DataObjectSet;
import seedpod.model.NoObjectFoundException;
import seedpod.model.SeedpodDO;
import seedpod.model.custom.AccessLog;
import seedpod.model.custom.SeedpodUser;
import seedpod.webapp.LimsSession;
import seedpod.webapp.Seedpod;


/*
 * this class manages web access to AccesLog. It logs into the database actions from the users. 
 * Queries for the latest logs. 
 */

public class Logger   {
	
	private static final long serialVersionUID = 1L;
	
	private LimsSession _session;
	
	public Logger(LimsSession session) {
		_session = session;
	}

	public static void write(SeedpodUser user, String event) {
		try {
			AccessLog log = new AccessLog(user, event, user.getManager());
			log.create();
		}
		catch (NoObjectFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (SeedpodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public   ArrayList<String> getLast(int num) {
		DataObjectSet logSet = new DataObjectSet(AccessLog.CLASSTYPE, Seedpod.getPManager() );
		ArrayList<String> logStrings = new ArrayList<String>();
		try {
			ArrayList<SeedpodDO> accessLogs = logSet.query( 10 );
			for ( SeedpodDO obj : accessLogs )
				logStrings.add( obj.getLabel() );
		}
		catch (SeedpodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return logStrings;
	}

}

